<template>
  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header>
      <div class="logo">
        <img src="../assets/images/header.gif" alt="" />
      </div>
      <div class="item" v-for="item in navigationList" :key="item.id">
        <img :src="require(`../assets/images/${item.icon}`)" alt="" />
        <span>{{ item.name }}</span>
      </div>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside style="width: 200px">
        <!-- 侧边栏菜单区域 -->
        <el-menu
          :default-active="activePath"
          class="el-menu-vertical-demo"
          background-color="#2a3139"
          text-color="#fff"
          unique-opened
          :collapse-transition="false"
          :router="true"
          active-text-color="#409eff"
        >
          <!-- 菜单 -->
          <el-submenu
            v-for="item in menuList"
            :key="item.id"
            :index="item.path"
          >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item
              v-for="key in item.children"
              :key="key.id"
              :index="key.path"
              @click="saveNavState(key.path)"
            >
              {{ key.name }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      // 菜单栏数据
      menuList: [
        {
          id: 0,
          name: "功能功能功能A",
          path: "1",
          icon: "el-icon-document",
          children: [
            {
              id: 0,
              name: "新增二级商协议",
              path: "agreement",
            },
          ],
        },
        {
          id: 1,
          name: "功能功B",
          path: "2",
          icon: "el-icon-suitcase-1",
          children: [
            {
              id: 1,
              name: "功能1",
              path: "notFound",
            },
          ],
        },
        {
          id: 2,
          name: "功能功能C",
          path: "3",
          icon: "el-icon-top-right",
          children: [
            {
              id: 2,
              name: "功能1",
              path: "notFound",
            },
          ],
        },
        {
          id: 3,
          name: "功能功能功能D",
          path: "4",
          icon: "el-icon-male",
          children: [
            {
              id: 3,
              name: "功能1",
              path: "notFound",
            },
          ],
        },
        {
          id: 4,
          name: "功能功能F",
          path: "5",
          icon: "el-icon-folder-checked",
          children: [
            {
              id: 4,
              name: "功能1",
              path: "notFound",
            },
          ],
        },
        {
          id: 5,
          name: "功能功能F",
          path: "6",
          icon: "el-icon-setting",
          children: [
            {
              id: 5,
              name: "功能1",
              path: "notFound",
            },
          ],
        },
      ],
      // 头部导航栏
      navigationList: [
        {
          id: 0,
          icon: "home_icon.gif",
          name: "首页",
        },
        {
          id: 1,
          icon: "information_icon.gif",
          name: "主数据",
        },
        {
          id: 2,
          icon: "manage_icon.gif",
          name: "辖区管理",
        },
        {
          id: 3,
          icon: "communication_icon.gif",
          name: "",
        },
      ],
      // 被激活的子菜单地址
      activePath: "",
    };
  },
  components: {},
  created() {
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    // 保存菜单的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
};
</script>

<style lang="scss" scoped>
.home_container {
  height: 100%;
}

.el-header {
  display: flex;
  align-items: center;
  height: 80px !important;
  padding: 0;
  line-height: 80px;
  font-size: 20px;
  background-color: #2a3139;

  .logo {
    position: relative;
    width: 200px;
    height: 80px;
    margin-right: 60px;
    box-shadow: 20px -16px 16px #000;
    z-index: 99;
  }

  .item {
    display: flex;
    align-items: center;
    height: 80px;
    color: #eeeeee;
    cursor: pointer;

    img {
      // width: 40px;
      height: 40px;
      border-radius: 8px;
    }

    span {
      margin-left: 15px;
      margin-right: 50px;
    }
  }
}
.el-container {
  .el-aside {
    background-color: #2a3139;
    .el-menu {
      border: none;
    }
  }
  .el-main {
    padding-bottom: 0;
    background-color: #f5f5f5;
    // 设置主体部分超出滚动
    // height: calc(100vh - 60px);
  }
}
</style>
